package com.qike.yuandongguoji.controller;

import com.qike.yuandongguoji.dto.*;
import com.qike.yuandongguoji.enums.ErrorEnums;
import com.qike.yuandongguoji.response.BaseResult;
import com.qike.yuandongguoji.response.RetResponse;
import com.qike.yuandongguoji.service.WeChatService;
import com.qike.yuandongguoji.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;

//import com.wuba.baojie.dto.VideorDto;

/**
 * @Author: Eric.zhou
 * @Date: 2019/6/3 14:33
 */
@RestController
@Api("微信用户控制")
@RequestMapping("/wechat")
@CrossOrigin
public class WeChatController {


    @Autowired
    private WeChatService weChatService;

    @ApiOperation("登录")
    @PostMapping("/login")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name = "code", value = "微信code", required = true, example = "1")
    })
    @ResponseBody
    public BaseResult login(@NotEmpty(message = "参数不能为空") @RequestParam("code") String code) throws URISyntaxException, IOException {
        try {
            LoginVo loginVo = weChatService.weChatLogin(code);
            return RetResponse.makeOKRsp(loginVo);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(ErrorEnums.ERROR_SYSTEM.getEmsg());
        }
    }


    @ApiOperation("获取手机号")
    @PostMapping("/getPhoneNumber")
    @ResponseBody
    public BaseResult getPhoneNumber(@RequestBody PhoneNumberDto phoneNumberDto) throws URISyntaxException, IOException {
        try {
            Object phoneNumber = weChatService.getPhoneNumber(phoneNumberDto);
            return RetResponse.makeOKRsp(phoneNumber);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }


    @ApiOperation("获取用户id")
    @GetMapping("/getUid")
    @ResponseBody
    public BaseResult getUid( GetUidDto getUidDto) throws URISyntaxException, IOException {
        try {
            GetUidVo uid = weChatService.getUid(getUidDto);
            return RetResponse.makeOKRsp(uid);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    @ApiOperation("获取用户状态")
    @GetMapping("/getUserStatus")
    @ResponseBody
    public BaseResult getUserStatus( GetUidDto getUidDto) throws URISyntaxException, IOException {
        try {
            Boolean flag = weChatService.getUserStatus(getUidDto);
            return RetResponse.makeOKRsp(flag);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    @ApiOperation("差旅行程列表")
    @GetMapping("/outList")
    @ResponseBody
    public BaseResult outList( OutListWeChatDto getUidDto) throws URISyntaxException, IOException {
        try {
          WechatOutListVo vo =  weChatService.outList(getUidDto);
            return RetResponse.makeOKRsp(vo);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }


    @ApiOperation("我要请假")
    @PostMapping("/addLeaving")
    @ResponseBody
    public BaseResult addLeaving( @RequestBody AddLeavingDto addLeavingDto) throws URISyntaxException, IOException {
        try {
             weChatService.addLeaving(addLeavingDto);
            return RetResponse.makeOKRsp();
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    @ApiOperation("请假撤回")
    @PostMapping("/delLeaving")
    @ResponseBody
    public BaseResult delLeaving( @RequestBody DelLeavingDto delLeavingDto) throws URISyntaxException, IOException {
        try {
            weChatService.delLeaving(delLeavingDto);
            return RetResponse.makeOKRsp();
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }


    @ApiOperation("我的审批单列表")
    @GetMapping("/myLeavingList")
    @ResponseBody
    public BaseResult myLeavingList( OutListWeChatDto getUidDto) throws URISyntaxException, IOException {
        try {
            MyLeavingListVo vo =    weChatService.myLeavingList(getUidDto);
            return RetResponse.makeOKRsp(vo);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }


    @ApiOperation("待我审批列表")
    @GetMapping("/waitMyLeavingList")
    @ResponseBody
    public BaseResult waitMyLeavingList( OutListWeChatDto getUidDto) throws URISyntaxException, IOException {
        try {
            WaitMyLeavingListVo vo = weChatService.waitMyLeavingList(getUidDto);
            return RetResponse.makeOKRsp(vo);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    @ApiOperation("审批")
    @PostMapping("/approval")
    @ResponseBody
    public BaseResult approval( @RequestBody ApprovalDto approvalDto) throws URISyntaxException, IOException {
        try {
             weChatService.approval(approvalDto);
            return RetResponse.makeOKRsp();
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }


    @ApiOperation("testNotice")
    @PostMapping("/testNotice")
    @ResponseBody
    public BaseResult testNotice( ) throws URISyntaxException, IOException {
        try {
            weChatService.testNotice();
            return RetResponse.makeOKRsp();
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }





    







}
